package com.syni.mdd.yhd.common.all.quartz.businessCoupon.job;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.entity.BmsBusinessCoupon;
import com.syni.mdd.yhd.common.all.entity.BmsDxOrder;
import com.syni.mdd.yhd.common.all.service.BmsBusinessCouponService;
import com.syni.mdd.yhd.common.all.service.BmsDxOrderService;
import com.syni.mdd.yhd.common.all.service.impl.BmsBusinessCouponServiceImpl;
import com.syni.mdd.sjb.common.component.utils.common.utils.SpringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.io.Console;
import java.util.Map;

/**
 * @className CouponToSendJob
 * @description TOO
 * @Author cfx
 * @DATE 2019/10/14 16:43
 * @VERSION 1.0
 **/
public class CouponToSendJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("........执行派发.........");
        BmsBusinessCouponService bmsBusinessCouponService = (BmsBusinessCouponService) SpringUtils.getBean(BmsBusinessCouponService.class);
        Map<String,Object> paramsMap = jobExecutionContext.getJobDetail().getJobDataMap();
        Integer couponId = Integer.parseInt(paramsMap.get("couponId").toString());
        BmsBusinessCoupon businessCoupon =  bmsBusinessCouponService.getBaseDao().findByIdAndIsDelete(couponId,Constants.COMMON_FLAG_FALSE_INT);
        if(businessCoupon != null) {
            if(businessCoupon.getStatus() == Constants.COUPON_STAY_OUT) {
                businessCoupon.setStatus(Constants.COUPON_START);
                bmsBusinessCouponService.getBaseDao().save(businessCoupon);
                System.out.println("........派发执行完成.........");
            }
        }
    }
}
